package com.example.orderflow.controller.ordergenerate;

import com.example.orderflow.controller.base.ABaseController;
import com.example.orderflow.entity.vo.ResponseVO;
import com.example.orderflow.exception.BusinessException;
import com.example.orderflow.service.OrderIdGenerationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @ClassName OrderNumberGenerationAccordingOrderTypeController
 * @Description: 根据订单类型获取最新订单编号
 * @Since JDK 1.8
 * @Create 2024/7/12 16:07
 */

@RestController
public class OrderNumberGenerationController extends ABaseController {

    @Autowired
    OrderIdGenerationService orderIdGenerationService;

    /**
     * @create: 2024/7/12 16:07
     * @description: 根据订单类型获取最新订单编号
     * @param: orderType 订单类型
     * @return orderId
     */
    @PostMapping ("/OrderNumberGeneration")
    protected <T> ResponseVO orderNumberGeneration(@RequestBody Map<String,String> map) {

        String orderType = map.get("orderType");
        String orderTypeUse;

        if (orderType.equals("销售订单")){ orderTypeUse = "XS"; }
        else if (orderType.equals("样品订单")){ orderTypeUse = "YP"; }
        else if(orderType.equals("售后订单")){ orderTypeUse = "SH"; }
        else { throw new BusinessException("错误的订单类型"); }

        return getSuccessResponseVO(orderIdGenerationService.generateNewOrderId(orderTypeUse));

    }
}
